package cn.leida.ruoyi.framework.jpa.jpa;

import cn.leida.common.time.util.BaseDateUtil;
import cn.leida.ruoyi.common.annotation.Excel;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * JPA 时间类型
 * MappedSuperclass :  子类表中自动创建属性
 *
 * @author ruoyi
 */
@Data
@MappedSuperclass
public class JPATimeEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 数据时间: 1744368553898
     */
    @Excel(name = "数据时间")
    @Column(name = "data_time", length = 64)
    protected Long dataTime;

    /**
     * 日期: 20250102
     * yyyyMMddHHmm
     */
    @Excel(name = "日期")
    @Column(name = "data_day")
    protected Long dataDay;

    /**
     * 24小时: 0-23
     */
    @Excel(name = "小时")
    @Column(name = "data_hour")
    protected Long dataHour;

    public void initTime(Date date) {
        try {
            this.setDataTime(date.getTime());
            this.setDataDay(BaseDateUtil.timeDayLong(date));
            this.setDataHour(BaseDateUtil.dayHour(date));
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}
